<?php $this->headLink()->appendStylesheet($this->UiCss('ui.all.css'))
->appendStylesheet($this->Css('button.css'));
$this->headScript()->appendFile($this->js('jquery.js'))
->appendFile($this->js('plugins/jquery.selectboxes.js'))
?>
<style type="text/css">
#classList { margin:10px;padding:2px;overflow:auto; height:300px;width:500px;background:#dde}

#list_teacher span  a {margin:5px;padding:5px;}
#list_teacher a {text-decoration:none;}
.class_detail {background:#ffe;margin:5px;padding:5px;}
.class_detail li {margin:3px;cursor:pointer;}
.selected {background:#ff0}
.teacher_selected {background:#ff0}

</style>
<script type="text/javascript">

var teachers_arr = <?php echo $this->teachers?>;
var teachers_sn = <?php echo $this->teachers_sn?>;
$(document).ready(function(){
	$("#year_semester").change(function(){
		$("#setform").submit();
	});
	$("#teacher_select").addOption(teachers_sn,false);
	$("#teacher_select").change(function(){
		$(".select_box").empty();
	});

	$(".class_detail a").click(function(){
		$(".selected").removeClass('selected');
		$(".select_box").empty();
		$(this).addClass('selected');
		$(this).siblings('div').children('.select_box').html("<select></select>");
		var id = $("#teacher_select option:selected").text();
		var aa = teachers_arr[id];
		$(".select_box select").addOption('','<?php echo $this->translate('select')?> '+id);
		$.each(aa,function(i,data){
		$(".select_box select").addOption(data.username,data.name);
		});
		$(".select_box select").selectOptions('');

	});

	$(".select_box select").live('change',function(){
		var teacher_id = $(this).val();
		if (teacher_id=='')
			return;
		var class_sn = $(".selected").attr('id').substr(2);
		var year_semester = $("#year_semester").val();
		if ($("#change_mode").attr('checked'))
			var checked =1 ;
		else
			var checked = 0;
		$.getJSON('<?php echo $this->route('set')?>',{year_semester:year_semester,class_sn: class_sn,teacher_id:teacher_id,delete:checked},function(data){
			var ss = '';
			$.each(data,function(){
				var name = $(".select_box select option[value="+this.teacher_id+"]").text();
				ss += name+ '  ';
			});
			$("#t-"+class_sn).html(ss);
		});
	});

});
</script>
<form id="setform" action="" method="post">
<select name="year_semester" id="year_semester">
<?php echo  $this->YearSemesterOptions($this->year_semester) ?>
</select> <label for="teacher_select"><?php echo $this->translate('choose title')?></label>
<select id="teacher_select"></select>
<label for="change_mode"><?php echo $this->translate('replace the original set')?></label>
<input id="change_mode" type="checkbox" value="1" checked="checked">
</form>
<h2><?php echo $this->translate('class list')?></h2>
<div id="classList">
<?php foreach($this->class_name as  $id=>$val):?>
<ul><li>
<h3><?php echo $id?></h3>
<ul class="class_detail">
<?php foreach($val as $class_sn=>$class_name):?>
<li  class="ui-widget ui-helper-clearfix">
<a id="c-<?php echo $class_sn?>"  class="fg-button ui-state-default fg-button-icon-left ui-corner-all">
<span class="ui-icon ui-icon-plusthick"></span>
<?php echo $class_name?></a>
<div>
<span class="select_box"></span>
<span id="t-<?php echo $class_sn?>">
<?php if($this->toturs[$class_sn]):?>
<?php foreach($this->toturs[$class_sn] as $tt):?>
<?php echo $tt['name']?>   <?php endforeach;?>
</span>
<?php endif?>
</div>
</li>
<?php endforeach;?>
</ul>
</li>
</ul>
<?php endforeach;?>
</div>

</div>

<div style="clear:both"></div>